import * as api from "./api";
import { CreateCrudOptionsProps, CreateCrudOptionsRet, dict } from "@fast-crud/fast-crud";

export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  const pageRequest = async (query) => {
    return await api.GetList();
  };
  const editRequest = async ({ form, row }) => {
    form.id = row.id;
    return await api.UpdateObj(form);
  };
  const delRequest = async ({ row }) => {
    return await api.DelObj(row.id);
  };
  const addRequest = async ({ form }) => {
    return await api.AddObj(form);
  };
  return {
    crudOptions: {
      request: {
        pageRequest,
        delRequest,
        addRequest,
        editRequest
      },
      columns: {
        id: {
          title: "ID",
          type: "number",
          column: {
            width: 50
          },
          form: { show: false }
        },
        username: {
          title: "用户名",
          type: "string"
        },
        password: {
          title:'密码',
          type: "string",
          column:{
            show:false
          },
          form: { show: true }

        },
        email: {
          title: "邮箱",
          type: "string"
        },
        tel: {
          title: "电话",
          type: "string"
        },
        gender: {
          title: "性别",
          type: "dict-select",
          dict: dict({
            data: [
              { label: "男", value: "M" },
              { label: "女", value: "F" },
              { label: "未知", value: "U" }
            ]
          })
        },
        last_login: {
          title: "最后登录时间",
          type: "datetime"
        },
        date_joined: {
          title: "注册时间",
          type: "datetime"
        }
      }

    }
  };
}
